<?php

/**
 * This is the model class for table "MoodHvacs".
 *
 * @author Julot
 * @since Wednesday, February 16th, 2011
 *
 * The followings are the available columns in table 'MoodHvacs':
 * @property integer $_id
 * @property integer $moodId
 * @property integer $hvacId
 * @property integer $value
 */
class MoodHvacs extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return MoodHvacs the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'MoodHvacs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('moodId, hvacId', 'numerical', 'integerOnly'=>true),
			array('value', 'required'),
			array(
				'value',
				'NumberValidator',
				'integerOnly'=>true,
				'allowEmpty'=>false,
				'dependOnAttribute'=>'hvac.hasRange',
				'minAttribute'=>'hvac.minValue',
				'maxAttribute'=>'hvac.maxValue',
			),
			
			// Rules for insert scenario
			array('hvacId', 'required', 'on'=>'insert'),
			
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('_id, moodId, hvacId, value', 'safe', 'on'=>'search'),
		);
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mood'=>array(self::BELONGS_TO, 'Mood', 'moodId'),
			'hvac'=>array(self::BELONGS_TO, 'Hvac', 'hvacId'),
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'_id' => 'ID',
			'moodId' => 'Mood',
			'mood.name' => 'Mood',
			'hvacId' => 'Device',
			'hvac.name' => 'Device',
			'value' => 'Value',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('_id',$this->_id);
		$criteria->compare('moodId',$this->moodId);
		$criteria->compare('hvacId',$this->hvacId);
		$criteria->compare('value',$this->value);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}